package com.quarkus.cloud.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.quarkus.cloud.domain.entity.User;
import com.quarkus.cloud.repository.UserMapper;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;

/**
 * @author zhuhb-a
 */
@Singleton
public class UserService {

    @Inject
    private UserMapper userMapper;

    public User findById(Long id) {
        return userMapper.selectById(id);
    }

    public Page<User> list(String name, String address, Integer age, Integer pageNo, Integer pageSize) {
        Page<User> page = userMapper.selectPage(new Page<>(pageNo, pageSize), new QueryWrapper<User>()
                .eq(StringUtils.isNotBlank(name), "name", name)
                .eq(StringUtils.isNotBlank(address), "address", address)
                .eq(null != age, "age", age));
        return page;
    }


    public boolean insert(User user) {
        return userMapper.insert(user) > 0;
    }

    public boolean update(User user) {
        return userMapper.updateById(user) > 0;
    }

    public boolean delete(Long id) {
        return userMapper.deleteById(id) > 0;
    }

}


